package com.xiaoshuidi.cloud.module.report.dal.mapper.report;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.module.report.dal.DO.report.OwnerIncomeDetailDayReportDO;
import com.xiaoshuidi.cloud.module.report.dal.DO.report.OwnerIncomeDetailReportDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
@InterceptorIgnore(tenantLine = "true")
public interface OwnerIncomeDetailDayReportMapper extends BaseMapperX<OwnerIncomeDetailDayReportDO> {


    @Select(" select count(1) from (select count(id) " +
            " from report_owner_income_detail_day " +
            " where statistics_month = #{currentMonth} group by contract_id) as temp")
    long countDetailsInCurrentMonth(@Param("currentMonth")String currentMonth);


    @Select("select * from report_owner_income_detail_day where contract_id =#{contractId}")
    List<OwnerIncomeDetailDayReportDO> selectByContractId(@Param("contractId")Long contractId);

    @Select(" select apartment_id,owner_name,owner_phone,room_name, room_id,contract_id,tenant_id,dept_id,contract_period ,area,house_resource,contract_no,statistics_month,month_rent ," +
            " sum(cur_rent_in) cur_rent_in,sum(cur_rent_disc) cur_rent_disc,sum(cur_rent_reduce) cur_rent_reduce, " +
            "  sum(cur_rent_in) acc_rent_in,sum(cur_rent_disc) acc_rent_disc,sum(cur_rent_reduce) acc_rent_reduce," +
            " sum(cur_other_in) cur_other_in,sum(cur_other_in) acc_other_in" +
            " from report_owner_income_detail_day " +
            " where  statistics_month = #{statisticsMonth} " +
            "  group by contract_id")
    List<OwnerIncomeDetailReportDO> selectOwnerDetailsInCurrentMonth(@Param("statisticsMonth")String currentMonth);


    @Select("select * from  report_owner_income_detail_day where contract_id = #{contractId} order by id desc limit 1")
    OwnerIncomeDetailReportDO selectLastOneByContractID(@Param("contractId")Long contractId);
 }
